<?php

require_once("function.php");

class RegularEmployee
{
	
	function deletePlanholder($polnum){
		$con = connectToDB();
		$pno = mysql_real_escape_string($polnum);
		
		//mysql_select_db("apodb", $con);

		$result = mysql_query("DELETE FROM planholder WHERE Policy_no='$pno'");
		
		if (!$result) {
			die('Invalid query: ' . mysql_error());
		}else{
			echo "Planholder Deleted.\n";
		}
	}
	
	function showInfo($polnum){
			$con4 = connectToDB();
			$polno = mysql_real_escape_string($polnum);
		
			$result = mysql_query("select * from planholder where Policy_no = '$polno'");
		
			//mysql_close($con);
			return $result;
	
	}
	
	
	function addPlanholder($policyNumber, $firstName, $middleName, $lastName, $contactNo, $birthday, $applicationNo, $accountExecutive, $type, $term, $mode, $planValue, $effectiveDate, $dueDate, $branch)
	{
		$conto = connectToDB();		
		$policyNumber = mysql_real_escape_string($policyNumber);
		$firstName = mysql_real_escape_string($firstName);
		$middleName = mysql_real_escape_string($middleName);
		$lastName = mysql_real_escape_string($lastName);
		$contactNo = mysql_real_escape_string($contactNo);
		$birthday = mysql_real_escape_string($birthday);
		$applicationNo = mysql_real_escape_string($applicationNo);
		$accountExecutive = mysql_real_escape_string($accountExecutive);
		$type = mysql_real_escape_string($type);
		$term = mysql_real_escape_string($term);
		$mode = mysql_real_escape_string($mode);
		$planValue = mysql_real_escape_string($planValue);
		$effectiveDate = mysql_real_escape_string($effectiveDate);
		$dueDate = mysql_real_escape_string($dueDate);
		$branch = mysql_real_escape_string($branch);
		
		$result = mysql_query("INSERT INTO planholder VALUES('$policyNumber', '$applicationNo','$firstName', '$middleName', '$lastName', '$effectiveDate', '$dueDate', '$branch', '$mode', '$type', '$planValue',  '$term','$birthday','DATEDIFF(CURDATE(),'$birthday')/365)','$accountExecutive')");
		if (!$result) {
			die('Invalid query: ' . mysql_error());
		}
	
	}
	
	function viewStartedContracts($empno)
	{
		$con2 = connectToDB();
		$emp_no = mysql_real_escape_string($empno);
		
		$result = mysql_query("select * from planholder where (Account_executive='$emp_no') order by Effective_date asc");
		
		//mysql_close($con2);
		return $result;
	}
	
	

	function editPlanholder($polnum,$firstName,$middleName,$lastName,$birthday,$applicationNo,$type,$term,$mode,$planValue,$effectiveDate,$dueDate,$branch){

	
		$con3 = connectToDB();		
		$policyNumber = mysql_real_escape_string($polnum);
		$firstName = mysql_real_escape_string($firstName);
		$middleName = mysql_real_escape_string($middleName);
		$lastName = mysql_real_escape_string($lastName);
		//$address = mysql_real_escape_string($address);
		//$contactNo = mysql_real_escape_string($contactNo);
		$birthday = mysql_real_escape_string($birthday);
		//$age = mysql_real_escape_string($age);
		$applicationNo = mysql_real_escape_string($applicationNo);
		//$accountExecutive = mysql_real_escape_string($accountExecutive);
		$type = mysql_real_escape_string($type);
		$term = mysql_real_escape_string($term);
		$mode = mysql_real_escape_string($mode);
		$planValue = mysql_real_escape_string($planValue);
		$effectiveDate = mysql_real_escape_string($effectiveDate);
		$dueDate = mysql_real_escape_string($dueDate);
		$branch = mysql_real_escape_string($branch);
		
		$result = mysql_query("UPDATE planholder SET Application_no='$applicationNo', First_name='$firstName', Middle_name='$middleName', Last_name= '$lastName', Effective_date='$effectiveDate', Due_date='$dueDate', Branch='$branch', Mode_of_payment='$mode', Type_of_plan='$type', Plan_value='$planValue', Term='$term', Bday='$birthday'  WHERE Policy_no = '$policyNumber' ");
		if (!$result) {
			die('Invalid query: ' . mysql_error());
		}else{
			echo"Planholder successfully edited!\n";
		}
	}
}

?>


